/*
 * Copyright 2017 - 2024 the original author or authors.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see [https://www.gnu.org/licenses/]
 */

package infra.jdbc.parsing;

/**
 * Created by lars on 22.09.2014.
 */
public class ForwardSlashCommentParser extends AbstractCommentParser {

  private boolean commentAlmostEnded;

  @Override
  protected void startParsing() {
    commentAlmostEnded = false;
  }

  @Override
  public boolean supports(char c, String sql, int idx) {
    return sql.length() > idx + 1 && c == '/' && sql.charAt(idx + 1) == '*';
  }

  @Override
  public boolean isEndComment(char c) {
    if (commentAlmostEnded && c == '/') {
      return true;
    }
    commentAlmostEnded = c == '*';
    return false;
  }
}
